<template>
  <div>
    <div style="padding: 5px 0">
      <el-input v-model="text" @keyup.enter.native="load" style="width: 200px"> <i slot="prefix" class="el-input__icon el-icon-search"></i></el-input>
      <el-button @click="add" type="primary" size="mini" style="margin: 10px">新增</el-button>
    </div>
    <el-table :data="tableData" border stripe style="width: 100%">
      <el-table-column prop="id" label="ID" width="100" sortable> </el-table-column>
      <el-table-column prop="orderMasterId" label="ID "></el-table-column>
      <el-table-column prop="orderMasterNumber" label="订单编号"></el-table-column>
      <el-table-column prop="userId" label="下单人ID"></el-table-column>
      <el-table-column prop="addressMessageName" label="收货人姓名"></el-table-column>
      <el-table-column prop="addressMessagePhone" label="电话"></el-table-column>
      <el-table-column prop="addressMessageProvince" label="省"></el-table-column>
      <el-table-column prop="addressMessageCity" label="市"></el-table-column>
      <el-table-column prop="addressMessageDistrict" label="区"></el-table-column>
      <el-table-column prop="addressMessageAddress" label="详细地址"></el-table-column>
      <el-table-column prop="orderMasterMoney" label="订单金额"></el-table-column>
      <el-table-column prop="orderMasterPaymoneyMethod" label="支付方式"></el-table-column>
      <el-table-column prop="orderMasterState" label="订单状态"></el-table-column>
      <el-table-column prop="orderMasterReceiveTime" label="收货时间"></el-table-column>
      <el-table-column prop="status" label="状态"></el-table-column>
      <el-table-column prop="deleted" label="逻辑删除"></el-table-column>
      <el-table-column prop="version" label="乐观锁"></el-table-column>
      <el-table-column prop="createTime" label="创建时间"></el-table-column>
      <el-table-column prop="updateTime" label="修改时间"></el-table-column>

      <el-table-column
          fixed="right"
          label="操作"
          width="200">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" circle  @click="edit(scope.row)"></el-button>
          <el-popconfirm
              @confirm="del(scope.row.id)"
              title="确定删除？"
          >
            <el-button type="danger" icon="el-icon-delete" circle slot="reference" style="margin-left: 10px"></el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 10px">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-size="pageSize"
        :page-sizes="[2, 5, 10]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <!-- 弹窗   -->
    <el-dialog title="信息" :visible.sync="dialogFormVisible" width="30%"
               :close-on-click-modal="false">
      <el-form :model="entity">
        <el-form-item label="ID " label-width="150px">
          <el-input v-model="entity.orderMasterId" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="订单编号" label-width="150px">
          <el-input v-model="entity.orderMasterNumber" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="下单人ID" label-width="150px">
          <el-input v-model="entity.userId" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="收货人姓名" label-width="150px">
          <el-input v-model="entity.addressMessageName" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="电话" label-width="150px">
          <el-input v-model="entity.addressMessagePhone" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="省" label-width="150px">
          <el-input v-model="entity.addressMessageProvince" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="市" label-width="150px">
          <el-input v-model="entity.addressMessageCity" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="区" label-width="150px">
          <el-input v-model="entity.addressMessageDistrict" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="详细地址" label-width="150px">
          <el-input v-model="entity.addressMessageAddress" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="订单金额" label-width="150px">
          <el-input v-model="entity.orderMasterMoney" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="支付方式" label-width="150px">
          <el-input v-model="entity.orderMasterPaymoneyMethod" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="订单状态" label-width="150px">
          <el-input v-model="entity.orderMasterState" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="收货时间" label-width="150px">
          <el-date-picker style="width: 80%" v-model="entity.orderMasterReceiveTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间"></el-date-picker>
        </el-form-item>
        <el-form-item label="状态" label-width="150px">
          <el-input v-model="entity.status" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="逻辑删除" label-width="150px">
          <el-input v-model="entity.deleted" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="乐观锁" label-width="150px">
          <el-input v-model="entity.version" autocomplete="off" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="创建时间" label-width="150px">
          <el-date-picker style="width: 80%" v-model="entity.createTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间"></el-date-picker>
        </el-form-item>
        <el-form-item label="修改时间" label-width="150px">
          <el-date-picker style="width: 80%" v-model="entity.updateTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间"></el-date-picker>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import API from '../../utils/request'
const url = "/api/msslyyOrderMaster/"

export default {
  name: "MsslyyOrderMaster",
  data() {
    return {
      fileList: [],
      options: [],
      text: '',
      user: {},
      tableData: [],
      pageNum: 1,
      pageSize: 10,
      entity: {},
      total: 0,
      dialogFormVisible: false
    };
  },
  created() {
    this.user = sessionStorage.getItem("user") ? JSON.parse(sessionStorage.getItem("user")) : {}
    this.$emit('user', this.user);
    this.load()
  },
  methods: {
    fileSuccessUpload(res) {
      this.entity.file = "http://localhost:9999/files/" + res.data;
      this.fileList = [res.data]
      console.log(res)
    },
    handleSizeChange(pageSize) {
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum
      this.load()
    },
    load() {
       API.get(url + "/page", {
          params: {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            name: this.text
          }
       }).then(res => {
          this.tableData = res.data.records || []
          this.total = res.data.total
       })
    },
    add() {
      this.entity = {}
      this.fileList = []
      this.dialogFormVisible = true
    },
    edit(obj) {
      this.entity = JSON.parse(JSON.stringify(obj))
      this.fileList = []
      this.dialogFormVisible = true
    },
    save() {
      if (!this.entity.id) {
        API.post(url, this.entity).then(res => {
           if (res.code === '0') {
             this.$message({
               type: "success",
               message: "操作成功"
             })
           } else {
             this.$message({
               type: "error",
               message: res.msg
             })
           }
           this.load()
           this.dialogFormVisible = false
        })
      } else {
        API.put(url, this.entity).then(res => {
          if (res.code === '0') {
            this.$message({
              type: "success",
              message: "操作成功"
            })
          } else {
            this.$message({
              type: "error",
              message: res.msg
            })
          }
          this.load()
          this.dialogFormVisible = false
        })
      }
    },
    del(id) {
      API.delete(url + id).then(res => {
        this.$message({
          type: "success",
          message: "操作成功"
        })
        this.load()
      })
    }
  },
};
</script>

<style scoped>
</style>
